<?php
namespace app\home\model;
use \think\Db;
class TopicsModel
{
    /**
     * 列表
     */
    public function topicsList($id){
        $topicsList = Db::table('topics')
            ->where("community_id = $id and is_del = 0")
            ->order('report_time desc')
            ->limit('0, 1')
            ->select();
        return $topicsList;
    }

    /**
     * 话题列表
     */
    public function topics($id){
        $topics = Db::table('topics')
            ->where("community_id = $id and is_del = 0")
            ->order('report_time desc')
            ->select();
        return $topics;
    }

    /**
     * 发表话题
     */
    public function addTopics($data){
        $addTopics = Db::table('topics')->insert($data);
        return $addTopics;
    }

    /**
     * 删除话题
     */
    public function topicDel($id){
        $del = Db::table('topics')->where('id', $id)->update(['is_del' => 1]);
        return $del;
    }

    /**
     * 话题数量
     */
    public function topicsCount($id){
        $topicsCount = Db::table('topics')
            ->where("community_id = $id and is_del = 0")
            ->count();
        return $topicsCount;
    }

}